package com.skyjoo.search.lucene.index.search;

import java.io.IOException;
import java.util.List;

import org.apache.lucene.document.Document;
import org.apache.lucene.facet.FacetResult;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;

import com.skyjoo.search.lucene.common.DomainBase;

public class Result extends DomainBase {

    /**
     * 
     */
    private static final long serialVersionUID = -8076468956311931832L;

    private TopDocs           topDocs;

    private IndexSearcher     searcher;

    private List<FacetResult> facetResult;

    public List<FacetResult> getFacetResult() {
        return facetResult;
    }

    public void setFacetResult(List<FacetResult> facetResult) {
        this.facetResult = facetResult;
    }

    public TopDocs getTopDocs() {
        return topDocs;
    }

    public void setTopDocs(TopDocs topDocs) {
        this.topDocs = topDocs;
    }

    public IndexSearcher getSearcher() {
        return searcher;
    }

    public void setSearcher(IndexSearcher searcher) {
        this.searcher = searcher;
    }

    public ScoreDoc[] getScoreDocs() {
        return this.topDocs.scoreDocs;
    }

    public Document doc(int num) {
        try {
            return this.searcher.doc(num);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public boolean hasResult() {
        return this.topDocs != null && this.topDocs.scoreDocs != null && this.topDocs.scoreDocs.length > 0;
    }

}
